package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class Window extends JFrame {

	private static final long serialVersionUID = 1L;
	private GameCanvas canvas;
	private HighScore hs;

	private final int WIDTH = 800;
	private final int HEIGHT = 600;
	private final String TITLE = "Pacman";
	private final String EXIT_NAME = "Quit";
	private final String START_NAME = "Start game!";
	private final String HIGHSCORE_NAME = "See top scores";

	private JPanel jMain = null;

	private JButton jExit = null;
	private JButton jStart = null;
	private JButton jScore = null;
	private JPanel buttons = null;

	public Window() {
		setup();
		addItems();
	}

	private void setup() {
		this.setSize(WIDTH, HEIGHT);
		this.setTitle(TITLE);
		this.setVisible(true);
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setIgnoreRepaint(true);
	}

	private void addItems() {
		this.setContentPane(getMain());
		// this.add(getButtons());
		this.add(getCanvas(), BorderLayout.CENTER);
		// TODO: Menüü, nupud ja shit

	}

	public JPanel getMain() {
		if (jMain == null) {
			jMain = new JPanel();
			jMain.setLayout(new BorderLayout());
			jMain.setPreferredSize(new Dimension(WIDTH, HEIGHT));
		}
		return jMain;
	}

	public JButton getHighScoreButton() {
		if (jScore == null) {
			jScore = new JButton(HIGHSCORE_NAME);
		}
		return jScore;
	}

	public JButton getStartButton() {
		if (jStart == null) {
			jStart = new JButton(START_NAME);
		}
		return jStart;
	}

	public JButton getExitButton() {
		if (jExit == null) {
			jExit = new JButton(EXIT_NAME);
			jExit.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					System.exit(0);
				}
			});
		}
		return jExit;
	}

	public JPanel getButtons() {
		if (buttons == null) {
			buttons = new JPanel();
			buttons.setLayout(new BorderLayout());
			buttons.setPreferredSize(new Dimension(300, 100));
			buttons.add(getStartButton(), BorderLayout.NORTH);
			buttons.add(getHighScoreButton(), BorderLayout.CENTER);
			buttons.add(getExitButton(), BorderLayout.SOUTH);
			buttons.validate();
		}
		return buttons;
	}

	public GameCanvas getCanvas() {
		if (canvas == null) {
			canvas = new GameCanvas();
		}
		return canvas;
	}

}
